#include <Windows.h>
#include <stdio.h>

void ShowErrorMessage(HWND hwnd, HRESULT hResult)
{
    WCHAR wszErrorDesc[512] = { 0 };

    FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0,
                   wszErrorDesc, _countof(wszErrorDesc) - 1, NULL);

    swprintf_s(wszErrorDesc + wcslen(wszErrorDesc), 
               _countof(wszErrorDesc) - wcslen(wszErrorDesc) - 1, 
               L"\r\n(0x%08X)", hResult);

    MessageBox(hwnd, wszErrorDesc, L"Warning", MB_ICONWARNING);
}

HFONT CreateSimpleFont(HDC hdc, const WCHAR *fontName, int fontSize)
{
    LOGFONT lf = { 0 };

    lf.lfWidth = 0;
    lf.lfHeight = -MulDiv(fontSize, GetDeviceCaps(hdc, LOGPIXELSY), USER_DEFAULT_SCREEN_DPI);
    lf.lfItalic = FALSE;
    lf.lfUnderline = FALSE;
    lf.lfStrikeOut = FALSE;
    lf.lfCharSet = DEFAULT_CHARSET;
    lf.lfOutPrecision = OUT_TT_PRECIS;
    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH;
    wcscpy_s(lf.lfFaceName, LF_FACESIZE, fontName);
    lf.lfWeight = FW_DONTCARE;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfEscapement = 0;
    lf.lfOrientation = 0;

    return CreateFontIndirect(&lf);
}